(function($,root){
    
    var curDuration;//歌曲的总时长（秒）
    var frameId ;
    var stopTime = 0;//暂停时的时间
    var startTime;//开始之间
    //播放时间比
    var lastPer = 0;
    //把秒转换成分和秒
    function formatTime(duration){
        duration = Math.round(duration);//取整
        var minute = Math.floor(duration / 60);
        var second = duration - minute * 60;
        if(minute < 10){
            minute = "0" + minute;
        }
        if(second < 10){
            second = "0" + second;
        }
        return minute + ":" +second;
    }
    function renderAllTime(duration){
        lastPer = 0;
        curDuration = duration;
        var allTime = formatTime(duration);
        $scope.find(".all-time").html(allTime);
    }

    //渲染左侧时间（当前播放的时间）
    function start(per){
        lastPer = per === undefined ? lastPer:per; 
        startTime = new Date().getTime();//开始播放的时间（毫秒）
        function frame(){
            var curTime = new Date().getTime();//当前的时间（毫秒）
            var per = lastPer + (curTime - startTime) / (curDuration*1000) ;//播放的总时长的百分比
            frameId = requestAnimationFrame(frame);
            update(per);
        }
        frame();
    }

    //暂停播放
    function stop(){
        //标记下暂停的时间
        stopTime = new Date().getTime();
        lastPer = lastPer + (stopTime - startTime)/(curDuration*1000);
        cancelAnimationFrame(frameId);
    }

    //更行html
    function update(percent){
        var  time = formatTime(percent*curDuration);
              
        $scope.find('.current-time').html(time);
        //进度条
        var perX = '-' + (1 - percent)*100 + '%';
        $scope.find('.pro-top').css('transform','translateX('+ perX +')');
    }
    root.processor = {
        renderAllTime : renderAllTime,
        start:start,
        stop:stop,
        update:update
    }
})(window.Zepto,window.player || (window.player));